package com.dxl.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dxl.system.service.TypeService;
import com.dxl.system.model.Type;
import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.dxl.base.Result;
import java.util.List;

/**
 * <b> 文件类型控制器
 * </b><br><br><i>Description</i> :
 * <br>Date: 2019-10-03    <br>Author : dxl
 */
@Api(value = "文件类型接口",tags = {"文件类型--接口"})
@Controller
@RequestMapping("/type")
public class TypeController {

    @Autowired(required = false)
    private TypeService typeService;


    /**
     * <b> 插入文件类型
     * </b><br><br><i>Description</i> : 不能为空：文件类型后缀-type_suffix 打开文件的程序路径-exe_path ；不能重复：文件类型后缀-type_suffix  
     * @param type Type
     * @return com.dxl.base.Result Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "插入文件类型",notes = "不能为空：文件类型后缀-type_suffix 打开文件的程序路径-exe_path ；不能重复：文件类型后缀-type_suffix  ")
    @RequestMapping(value = "/addOne",method = {RequestMethod.POST })
    @ResponseBody
    public Result addOne(@Valid @RequestBody Type type) {
        Result result = typeService.addOne(type);
        return result;
    }

    /**
     * <b> 删除文件类型
     * </b><br><br><i>Description</i> : 
     * @param typeIds List: Integer
     * @return com.dxl.base.Result int
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "删除文件类型",notes = "无注意点！")
    @RequestMapping(value = "/delByIds",method = {RequestMethod.POST })
    @ResponseBody
    public Result delByIds(@RequestParam(value="typeIds", required = true) List<Integer> typeIds){
        Result result = typeService.delByIds(typeIds);
        return result;
    }

    /**
     * <b> 编辑文件类型
     * </b><br><br><i>Description</i> : 不能重复：文件类型后缀-type_suffix 
     * @param type Type
     * @return com.dxl.base.Result Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "编辑文件类型",notes = "不能重复：文件类型后缀-type_suffix ")
    @RequestMapping(value = "/editOne",method = {RequestMethod.POST })
    @ResponseBody
    public Result editOne(@Valid @RequestBody Type type) {
        Result result = typeService.editOne(type);
        return result;
    }

    /**
     * <b> ID查询文件类型
     * </b><br><br><i>Description</i> : 
     * @param typeId Integer
     * @return com.dxl.base.Result: Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "ID查询文件类型",notes = "无注意点！")
    @RequestMapping(value = "/getById",method = {RequestMethod.POST })
    @ResponseBody
    public Result getById(@RequestParam(value="typeId", required = true) Integer typeId) {
        Result result = typeService.getById(typeId);
        return result;
    }

    /**
     * <b> 条件查询文件类型
     * </b><br><br><i>Description</i> : 
     * @param type Type
     * @return com.dxl.base.Result List: Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "条件查询文件类型",notes = "无注意点！")
    @RequestMapping(value = "/getList",method = {RequestMethod.POST })
    @ResponseBody
    public Result getList(@Valid @RequestBody Type type) {
        Result result = typeService.getList(type);
        return result;
    }

    /**
     * <b> 分页条件查询文件类型
     * </b><br><br><i>Description</i> : 
     * @param type Type, currentPage -Integer
     * @return com.dxl.base.Result List: Type
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "分页条件查询文件类型",notes = "无注意点！")
    @RequestMapping(value = "/getListByPage",method = {RequestMethod.POST })
    public Result getListByPage(@Valid @RequestBody Type type, @RequestParam(value="currentPage", required = false, defaultValue = "1") Integer currentPage, @RequestParam(value="pageSize", required = false, defaultValue = "20") Integer pageSize) {
        Result result = typeService.getListByPage(type, currentPage, pageSize);
        return result;
    }

    /**
     * <b> 管理文件类型
     * </b><br><br><i>Description</i> :
     * @return com.dxl.base.Result List: Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "管理文件类型",notes = "无注意点！")
    @RequestMapping(value = "/getAllHtml",method = {RequestMethod.GET })
    public String getAllHtml(Model model) {
        List<Type> typeList = (List<Type>) typeService.getList(new Type()).getData();
        model.addAttribute(typeList);
        return "type/type";
    }
    /**
     * <b> 管理文件类型
     * </b><br><br><i>Description</i> :
     * @return com.dxl.base.Result List: Type
     * <br><br>Date: 2019-10-03    <br>Author : dxl
     */
    @ApiOperation(value = "管理文件类型",notes = "无注意点！")
    @RequestMapping(value = "/getAll",method = {RequestMethod.POST })
    @ResponseBody
    public Result getAll() {
        Result result = typeService.getList(new Type());
        return result;
    }

    /**
     * <b> 文件类型能否新增
     * </b><br><br><i>Description</i> : 无权限限制；不能为空：文件类型后缀-type_suffix 打开文件的程序路径-exe_path ；不能重复：文件类型后缀-type_suffix  
     * @param type Type
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "文件类型能否新增",notes = "无权限限制；不能为空：文件类型后缀-type_suffix 打开文件的程序路径-exe_path ；不能重复：文件类型后缀-type_suffix  ")
    @RequestMapping(value = "/isAddable",method = {RequestMethod.POST })
    public Result isAddable(@Valid @RequestBody Type type) {
        Result result = typeService.isTypeAddable(type);
        return result;
    }

    /**
     * <b> 文件类型能否编辑
     * </b><br><br><i>Description</i> : 无权限限制；不能重复：文件类型后缀-type_suffix 
     * @param type Type
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-10-03     <br>Author : dxl
     */
    @ApiOperation(value = "文件类型能否编辑",notes = "无权限限制；不能重复：文件类型后缀-type_suffix ")
    @RequestMapping(value = "/isEditable",method = {RequestMethod.POST })
    public Result isEditable(@Valid @RequestBody Type type) {
        Result result = typeService.isTypeEditable(type);
        return result;
    }
}
